/**
 * 
 */
package com.qolome.controller;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.qolome.dao.model.User;
import com.qolome.dto.request.UserDtoCreateRequest;
import com.qolome.enums.ResultEnum;
import com.qolome.service.UserService;
import com.qolome.utils.web.ErrReturnUtils;
import com.qolome.utils.web.HttpResult;

/**
 * @Description: 用户控制层
 * @author 姜锋
 * @date 2020年1月5日 下午2:28:32
 * @version V1.0
 */
@RestController
@RequestMapping("/user")
public class UserController {
	
	@Autowired
	UserService userService;
	
	
	@PostMapping("/create")
	public HttpResult<?> create(@RequestBody @Valid UserDtoCreateRequest user, BindingResult bindingResult) {
		if (bindingResult.hasErrors()) {
			return ErrReturnUtils.returnError(bindingResult.getAllErrors());
		}
		userService.create(user);
		return HttpResult.resultEnum(ResultEnum.SUCCESS, null);
	}
	
	@GetMapping("/{userId}")
	public HttpResult<User> selectByPrimaryKey( @PathVariable String userId){
		return HttpResult.success(userService.selectByPrimaryKey(userId), null);
	}
}
